package com.ljp.chat.controller;

import com.ljp.chat.client.CurrencyClient;
import com.ljp.chat.client.UploadFile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("currency")
public class FunctionController {

    private final UploadFile uploadFile;
    private final CurrencyClient currencyClient;

    //此处报错不影响
    public FunctionController(UploadFile uploadFile, CurrencyClient currencyClient) {
        this.uploadFile = uploadFile;
        this.currencyClient = currencyClient;
    }

    /**
     * Upload file string.
     * 文件上传接口
     *
     * @param file the file
     * @return the string
     */
    @PostMapping("file")
    public String uploadFile(MultipartFile file) {
        return uploadFile.uploadFile(file).get("data").toString();
    }

    /**
     * Get address by ip string.
     * 获得当前IP的归属地
     *
     * @return the string
     */
    @GetMapping("ip")
    public String getAddressByIp(){
        return currencyClient.getAddressByIp().get("data").toString();
    }
}
